<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="/WEB-INF/taglib.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>纳税主体信息</title>
    <%@ include file="/WEB-INF/jsp/include.jsp" %>
    <style type="text/css"></style>
    <script type="text/javascript">
        var path = "${path}";
        var params = new Object();
        var url = path+"/basicinfo/taxPayersInfo/queryByPage";

        var layer_jqobj_add;
        var layer_jqobj_edit;

        $(function () {
            setAjaxLoading();
            var grid = $("#tt");

            //或者组织树
            getOrgTree();
            //出售表格
            initGrid(grid);

        });

        //初始化表格和数据
        function initGrid(grid) {
            var columns = [
                {
                    field: "code",
                    title: "统一社会信用代码",
                    align: "center",
                    halign: "center",
                    sortable: false,
                    resizable: true,
                    width: 120
                },
                {
                    field: "name",
                    title: "纳税主体名称",
                    align: "center",
                    halign: "center",
                    sortable: false,
                    resizable: true,
                    width: 200
                },
                {
                    field: "orgCode",
                    title: "所属机构代码",
                    align: "center",
                    halign: "center",
                    sortable: false,
                    resizable: true,
                    width: 100
                },
                {
                    field: "regTypeName",
                    title: "注册类型",
                    align: "center",
                    halign: "center",
                    sortable: false,
                    resizable: true,
                    width: 80
                },
                {
                    field: "regTime",
                    title: "注册时间",
                    align: "center",
                    halign: "center",
                    sortable: false,
                    resizable: true,
                    width: 80
                },
                {
                    field: "taxAgent",
                    title: "税务经办人",
                    align: "center",
                    halign: "center",
                    sortable: false,
                    resizable: true,
                    width: 80
                },
                {
                    field: "fullName",
                    title: "生产经营地址",
                    align: "left",
                    halign: "center",
                    sortable: false,
                    resizable: true,
                    width: 250
                },
                {
                    field: "businessStatus",
                    title: "营业状态 ",
                    align: "center",
                    halign: "center",
                    sortable: false,
                    resizable: true,
                    width: 80,
                    formatter: function (value, row, index) {
                        var str = "";
                        if (value == "1") {
                            str = "营业";
                        } else if (value == "0") {
                            str = "停业";
                        }

                        return str;
                    }
                },
                {
                    field: "taxpayerQualification",
                    title: "增值税纳税人类型",
                    align: "center",
                    halign: "center",
                    sortable: false,
                    resizable: true,
                    width: 120,
                    formatter: function (value, row, index) {
                        var str = "";
                        if (value == "1") {
                            str = "一般纳税人";
                        } else if (value == "2") {
                            str = "小规模纳税人";
                        }

                        return str;
                    }
                },
            ];
            initPageGrid(grid, params, url, columns, "#tb");
            var grid_options = $("#tt").datagrid("options");
            grid_options.onDblClickRow = function (rowIndex, rowData) {
                btnView();
            }
            btnQuery();
        }

        // 重置查询条件
        function btnReset() {
            $("#sel_nszt").val("");
            $("#sel_taxCode").val("");
            $('#orgComb').combobox('clear');
        }

        //查询
        function btnQuery() {
            params.name = $("#sel_nszt").val();
            params.code = $("#sel_taxCode").val();
            params.orgCode = $('#orgComb').combobox('getValue');

            if (params.pageNo == "undefined" || params.pageNo == undefined) {
                params.pageNo = 1;
                params.page = 1;
                params.pageNumber = 1;
            }
            var grid = $("#tt");
            var url = path+"/basicinfo/taxPayersInfo/queryByPage";
            getPage(grid, params, url);
        }

        //增加
        function btnAdd() {
            top.layer.open({
                type: 2,
                title: '添加',
                shadeClose: false,
                shade: 0.3,
                area: ['1050px', '600px'],
                content: path+'/basicinfo/taxPayersInfo/toAdd',
                maxmin: true,
                end: function callback() {
                    btnQuery();
                }
            });
        }

        //修改
        function btnEdit() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length == 0) {
                $.alert("pick", "info", "明细项目");
                return;
            }
            var row = rows[0];
            var id = row.id;
            var url = path+'/basicinfo/taxPayersInfo/toUpdate?id=' + id;
            top.layer.open({
                type: 2,
                title: '修改',
                shadeClose: false,
                shade: 0.3,
                area: ['1050px', '600px'],
                content: url,
                maxmin: true,
                end: function callback() {
                    btnQuery();
                }
            });
        }

        //查看
        function btnView() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length == 0) {
                $.alert("pick", "info", "明细项目");
                return;
            }
            var row = rows[0];
            var id = row.id;
            var url = path+'/basicinfo/taxPayersInfo/toView?id=' + id;
            top.layer.open({
                type: 2,
                title: '查看',
                shadeClose: false,
                shade: 0.3,
                area: ['1050px', '600px'],
                content: url,
                maxmin: true
            });
        }


        //删除
        function btnDel() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length == 0) {
                $.alert("pick", "info", "明细项目");
                return;
            }
            var rowData = rows[0];
            var param = new Object();
            param.id = rowData.id;
            $.messager.alert("问题", "请确认是否要删除？","confirm", function () {
                    $.ajax({
                        type: "POST",
                        url: path+'/basicinfo/taxPayersInfo/delete',
                        data: param,
                        dataType: "json",
                        async: false,
                        success: function callback(data) {
                            var analyMsg = data;
                            if (analyMsg.code != "0000") {
                                $.alert("delete", "info", "纳税主体");
                            } else {
                                btnQuery();
                            }
                        }
                    });
            });
        }

        //增加-股东持股明细
        function btnAddGdcgMx() {
            layer.open({
                type: 2,
                title: '添加',
                shadeClose: false,
                shade: 0.3,
                area: ['800px', '420px'],
                content: '${path}/basicinfo/taxPayersInfo/toAddGdcg',
                success: function (layero, index) {
                },
            });
        }

        //修改-股东持股明细
        function btnEditGdcgMx(rowIndex, data) {
            layer.open({
                type: 2,
                title: '修改',
                shadeClose: false,
                shade: 0.3,
                area: ['800px', '420px'],
                content: '${path}/basicinfo/taxPayersInfo/toUpdateGdcg',
                success: function (layero, index) {
                    var iframe = layero.find("iframe")[0];
                    iframe.contentWindow.rowIndex = rowIndex;
                    iframe.contentWindow.setValue(data);
                },
            });
        }

        //查看-股东持股明细
        function btnViewGdcgMx(data) {
            layer.open({
                type: 2,
                title: '查看',
                shadeClose: false,
                shade: 0.3,
                area: ['800px', '420px'],
                content: '${path}/basicinfo/taxPayersInfo/toViewGdcg',
                success: function (layero, index) {
                    var iframe = layero.find("iframe")[0];
                    iframe.contentWindow.setValue(data);
                },
            });
        }

        //增加股东持股回调函数
        function callback_addGdcgMx(data) {
            var jquery_datagrid = null;
            var iframe = null

            if (typeof(layer_jqobj_add) != "undefined" && layer_jqobj_add != null) {
                iframe = layer_jqobj_add.find("iframe")[0];
                jquery_datagrid = iframe.contentWindow.$("#tt_gd");
            }

            if (typeof(layer_jqobj_edit) != "undefined" && layer_jqobj_edit != null) {
                iframe = layer_jqobj_edit.find("iframe")[0];
                jquery_datagrid = iframe.contentWindow.$("#tt_gd");
            }
            data.updateState = 1;
            jquery_datagrid.datagrid("appendRow", data);
            iframe.contentWindow.callback_addGdcgMx();
        }

        //修改股东持股回调函数
        function callback_editGdcgMx(rowIndex, data) {
            var jquery_datagrid = null;
            var iframe = null
            if (typeof(layer_jqobj_add) != "undefined" && layer_jqobj_add != null) {
                iframe = layer_jqobj_add.find("iframe")[0];
                jquery_datagrid = iframe.contentWindow.$("#tt_gd");
            }
            if (typeof(layer_jqobj_edit) != "undefined" && layer_jqobj_edit != null) {
                iframe = layer_jqobj_edit.find("iframe")[0];
                jquery_datagrid = iframe.contentWindow.$("#tt_gd");
            }
            var rows = jquery_datagrid.datagrid("getRows");
            var row = rows[rowIndex];
            row = $.extend(row, data);
            var updateState = row.updateState;
            if (typeof(updateState) == "undefined" || updateState == null) {
                row.updateState = 2;
            }
            var param = new Object();
            param.index = rowIndex;
            param.row = row;
            jquery_datagrid.datagrid("updateRow", param);
            iframe.contentWindow.callback_editGdcgMx();
        }

        //增加-股权关系明细
        function btnAddGqgxMx() {
            layer.open({
                type: 2,
                title: '添加',
                shadeClose: false,
                shade: 0.3,
                area: ['800px', '350px'],
                content: '${path}/basicinfo/taxPayersInfo/toAddGqgx',
                success: function (layero, index) {
                },
                end: function () {
                }
            });
        }

        //修改-股权关系明细
        function btnEditGqgxMx(rowIndex, data) {
            layer.open({
                type: 2,
                title: '修改',
                shadeClose: false,
                shade: 0.3,
                area: ['800px', '410px'],
                content: '${path}/basicinfo/taxPayersInfo/toUpdateGqgx',
                success: function (layero, index) {
                    var iframe = layero.find("iframe")[0];
                    iframe.contentWindow.rowIndex = rowIndex;
                    iframe.contentWindow.setValue(data);
                },
                end: function () {
                }
            });
        }

        //查看-股权关系明细
        function btnViewGqgxMx(data) {
            layer.open({
                type: 2,
                title: '查看',
                shadeClose: false,
                shade: 0.3,
                area: ['800px', '410px'],
                content: '${path}/basicinfo/taxPayersInfo/toViewGqgx',
                success: function (layero, index) {
                    var iframe = layero.find("iframe")[0];
                    iframe.contentWindow.setValue(data);
                },
                end: function () {
                }
            });
        }

        //增加股权关系回调函数
        function callback_addGqgxMx(data) {
            var jquery_datagrid = null;
            var iframe = null

            if (typeof(layer_jqobj_add) != "undefined" && layer_jqobj_add != null) {
                iframe = layer_jqobj_add.find("iframe")[0];
                jquery_datagrid = iframe.contentWindow.$("#tt_gq");
            }
            if (typeof(layer_jqobj_edit) != "undefined" && layer_jqobj_edit != null) {
                iframe = layer_jqobj_edit.find("iframe")[0];
                jquery_datagrid = iframe.contentWindow.$("#tt_gq");
            }
            data.updateState = 1;
            jquery_datagrid.datagrid("appendRow", data);
            iframe.contentWindow.callback_addGqgxMx();
        }

        //修改股权关系回调函数
        function callback_editGqgxMx(rowIndex, data) {
            var jquery_datagrid = null;
            var iframe = null

            if (typeof(layer_jqobj_add) != "undefined" && layer_jqobj_add != null) {
                iframe = layer_jqobj_add.find("iframe")[0];
                jquery_datagrid = iframe.contentWindow.$("#tt_gq");
            }
            if (typeof(layer_jqobj_edit) != "undefined" && layer_jqobj_edit != null) {
                iframe = layer_jqobj_edit.find("iframe")[0];
                jquery_datagrid = iframe.contentWindow.$("#tt_gq");
            }
            var rows = jquery_datagrid.datagrid("getRows");
            var row = rows[rowIndex];

            row = $.extend(row, data);
            var updateState = row.updateState;
            if (typeof(updateState) == "undefined" || updateState == null) {
                row.updateState = 2;
            }
            var param = new Object();
            param.index = rowIndex;
            param.row = row;
            jquery_datagrid.datagrid("updateRow", param);
            iframe.contentWindow.callback_editGqgxMx();
        }

        function initQcsj() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length == 0) {
                $.alert("pick", "info", "纳税主体信息");
                return;
            }
            top.layer.open({
                type: 2,
                title: '期初数据采集',
                shadeClose: false,
                shade: 0.3,
                area: ['100%', '100%'],
                content: '${path}/csh/cshZzszb/csh?nsztId=' + rows[0].id
            });
        }
        function btnXmxx() {
            var rows = $('#tt').datagrid('getSelections');
            if (rows.length == 0) {
                $.alert("pick", "info", "纳税主体信息");
                return;
            }
            top.layer.open({
                type: 2,
                title: '项目管理',
                shadeClose: false,
                shade: 0.3,
                area: ['900px', '510px'],
                content: '${path}/jcxx/xmxx/index?nsztId=' + rows[0].id
            });
        }


        function getOrgTree() {
            $.ajax({
                type: "POST",
                async: true,
                url: path+"/basicinfo/taxPayersInfo/queryByList/",
                data: params,
                dataType: "json",
                success: function (data) {
                    var analyMsg = data;
                    analyMsg.code == "0000"
                    if (analyMsg.code == "0000") {
                        var taxpayer = analyMsg.returnObject.rows;
                        $("#orgComb").combobox({
                            'valueField': 'code',
                            'textField': 'name',
                            'data': taxpayer
                        });
                    }
                },
            });
        }

    </script>
</head>
<body style="margin:0px; padding:0px;">
<%@ include file="/WEB-INF/jsp/loading.jsp" %>
<div class="easyui-layout" fit="true">
    <div region="center" style="padding: 5px;" border="false">
        <div class="easyui-layout" fit="true" border="false">
            <div id="divNorth" region="north" title="查询条件" border="true" noheader="false"
                 style="padding: 6px; height: 90px; background: none repeat scroll 0 0 #EFEFEF;">
                <table>
                    <tr>
                        <td>所属机构：</td>
                        <td>
                            <select id="orgComb" class="easyui-combobox" name="orgComb" onchange="change()"
                                    data-options="panelWidth:250"
                                    style="width: 250px;">
                            </select>
                        </td>
                        <td></td>
                        <td>统一社会信用代码：</td>
                        <td>
                            <input type="text" id="sel_taxCode" name="sel_taxCode" style="width: 150px;"/>
                        </td>
                        <td></td>
                        <td>纳税主体名称：</td>
                        <td>
                            <input type="text" id="sel_nszt" name="sel_nszt" style="width: 150px;"/>
                        </td>
                        <td><input class="search-btn-blue" style="margin-left:10px" type="button" onclick="btnQuery();"
                                   value="查询"></td>
                        <td><input class="search-btn-blue" style="margin-left:10px" type="button" onclick="btnReset();"
                                   value="重置"></td>
                    </tr>
                </table>
            </div>
            <div region="center" title="" border="false" noheader="true" style="padding: 5px 0 0 0;">
                <table id="tt" title="" border="true"></table>
            </div>
        </div>
    </div>
</div>
<div id="tb" style="padding: 1px; height: auto; display: none;">
    <div>
        <a id="btn_add_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="false"
           onclick="btnAdd()">新增</a>
        <a id="btn_edit_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="false"
           onclick="btnEdit()">修改</a>
        <a id="btn_del_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="false"
           onclick="btnDel()">删除</a>
        <a id="btn_view_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-search" plain="false"
           onclick="btnView()">查看</a>
    </div>
</div>
</body>
</html>
